<?php
class regAction extends security_normal {
	
	function action(){
		if(ConfigV('micefun','user_reg')==0){
			MessageBox('会员注册功能已关闭','back');
			exit;
		}

		$miceSession = new session();
		if($miceSession->get('mu__userid')>0){
			MessageBox('您已登录系统！','back');
			exit;
		}
		
		global $conn;
		if($_POST){
			if($_POST['checkcode']!=$miceSession->get('checkcode')){
				MessageBox('验证码错误','back');
				exit;
			}

			if($_POST['name']==''){
				MessageBox('请填写登录名','back');
				exit;
			}

			if($_POST['pwd1']==''){
				MessageBox('密码不能为空','back');
				exit;
			}

			if($_POST['pwd1']<>$_POST['pwd2']){
				MessageBox('密码和确认密码不一致','back');
				exit;
			}

			$salt = md5(rand(100000, 999999).$_POST['name']);
			$pwd=sha1($salt.$_POST['pwd2']);

			$user2=new model_User();
			$user2->setSubsection('WHERE loginname=\''.$_POST['name'].'\'');
			$results2=$user2->doSelectOne();

			if($results2){
				MessageBox('登录名已经被占用','back');
				exit;
			}

			$user=new model_User();
			$user->setLoginname($_POST['name']);
			$user->setSalt($salt);
			$user->setPassword($pwd);

			$user->setRealname($_POST['realname']);
			$user->setEmail(strtolower($_POST['email']));
			$user->setGroupId(ConfigV('micefun','user_reg_group'));
			$user->setStatus(0);
			$user->setTelno($_POST['telno']);
			$user->setRegdate(time());
			$user->setStopdate('0');
			$user->setLastlogindate(time());
			$user->setLastloginip(GetRealIp());
			$result=$user->doInsert();

			if($result){
				$exeresult='注册成功';
				$group=new model_Group();
					$group->setSubsection('WHERE group_id='.$user->getGroupId());
					$groups=$group->doSelectOne();

				$miceSession = new session();
				$miceSession->set('mu__loginname', $user->getLoginname());
						$miceSession->set('mu__userid', $user->getUserId());
						$miceSession->set('mu__groupid', $user->getGroupId());
						$miceSession->set('mu__grouplevel', $groups->getLevel());
						$miceSession->set('groupmenu', $groups->getMenu());
						$miceSession->set('groupmodule', $groups->getModule());
						MessageBox('注册成功',MICE_URL);
						exit;
			}else{
				$exeresult='注册失败';
				MessageBox($exeresult,MICE_URL);
				exit;
			}
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("name",$name);
		$smarty->assign("checkcode",MICE_URL.'code.php');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>